package com.github.rxyor.netty.exemple.case3;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;

/**
 *<p>
 *
 *</p>
 *
 * @author liuyang
 * @date 2020/5/23 周六 23:17:00
 * @since 1.0.0
 */
public class IdleServerHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt)
        throws Exception {
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent event = (IdleStateEvent) evt;
            System.out.println(String.format("[%s] %s",
                ctx.channel().remoteAddress(), event.state().name()));
            ctx.channel().close();
        }
    }
}
